﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MxTol.Managers.Helpers;
using System.Data;

namespace MxTol.Managers
{
    public class BaMultipleManager
    {
        /// <summary>
        /// 以Json分页格式返回所有多选题
        /// </summary>
        public static string GetAllMultiple(int currentPage, int pageSize)
        {
            string json = string.Empty;

            try
            {
                string sql = "select * from Ba_Multiple order by add_time desc;";
                json = PaginationHelper.GetJsonBySql(currentPage, pageSize, sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return json;
        }

        /// <summary>
        /// 以Json分页格式返回所有多选题
        /// </summary>
        public static string GetAllMultiple(int currentPage, int pageSize, string sql)
        {
            string json = string.Empty;

            try
            {
                json = PaginationHelper.GetJsonBySql(currentPage, pageSize, sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return json;
        }

        /// <summary>
        /// 获取会计基础多选题
        /// 注：返回20题，可随机返回20条记录或按照时间排序TOP 20
        /// </summary>
        public static DataTable GetMultiple(bool isNew = false)
        {
            DataTable table = null;
            try
            {
                // 随机20条
                string sql = @"select top 20 id,title,answer_a,answer_b,answer_c,answer_d,answer_key,analysis,NEWID() as random 
                               from Ba_Multiple order by random;";
                if (isNew)
                {
                    // 最新20条
                    sql = @"select top 20 id,title,answer_a,answer_b,answer_c,answer_d,answer_key,analysis 
                            from Ba_Multiple order by add_time desc;";
                }

                DataSet set = SqlHelper.ExecuteDataSet(ManagerConfig.ConnectionString, sql);
                if (set != null && set.Tables.Count > 0)
                {
                    table = set.Tables[0];
                }

                return table;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
